import { defineStore } from 'pinia';
import { ref } from 'vue';
import { GET_ENTIRE_DEPARTMENTS, GET_ENTIRE_MENUS, GET_ENTIRE_ROLES } from '@/api/main';

export const useMainStore = defineStore('main', () => {
  const stateEntireRoles = ref<any[]>();
  const stateEntireDepartments = ref<any[]>();
  const stateEntireMenus = ref<any[]>();

  async function actionFetchEntireData() {
    try {
      const rolesRes = await GET_ENTIRE_ROLES();
      const departmentsRes = await GET_ENTIRE_DEPARTMENTS();
      const menusRes = await GET_ENTIRE_MENUS();
      stateEntireRoles.value = rolesRes.list;
      stateEntireDepartments.value = departmentsRes.list;
      stateEntireMenus.value = menusRes.list;
    } catch (err) {
      console.warn(err);
    }
  }
  return {
    stateEntireRoles,
    stateEntireDepartments,
    stateEntireMenus,
    actionFetchEntireData
  };
});
